class Solution {
    public void duplicateZeros(int[] arr) {
        int cur = 0;
        int dest = -1;
        int n = arr.length;

        while(cur < n){
            if(arr[cur] == 0){
                dest = dest + 2;
            }else{
                dest ++;
            }
            if(dest >= n - 1){
                break;
            }
            cur ++;
        }
        if(dest == n){
            cur --;
            dest --;
            arr[dest --] = 0;
        }
        while(cur >= 0){
            if(arr[cur] == 0){
                arr[dest --] = 0;
                arr[dest --] = 0;
            }else{
                arr[dest --] = arr[cur];
            }
            cur --;
        }

    }
}